<template>
    <div>
        <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" :min-date="minDate" :max-date="maxDate"
            @cancel="$emit('close')" @confirm="onConfirm" />
    </div>
</template>
<script>
import { updateName } from '@/api/user'
import dayjs from 'dayjs'
export default {
    name: 'UpdateBirthday',
    data() {
        return {
            minDate: new Date(1970, 0, 1),
            maxDate: new Date(),
            currentDate: new Date(this.value)
        }
    },
    props: {
        value: {
            type: String,
            required: true
        }
    },
    created() {
    },
    computed: {
    },
    methods: {
        async onConfirm() {
            this.$toast.loading({
                messege: '完成中',
                forbidClick: true,
                duration: 0 //持续展示toast
            })
            try {
                const birthday = dayjs(this.currentDate).format("YYYY-MM-DD")
                await updateName({
                    birthday: birthday
                })
                // 1-更新视图 2-关闭弹出层 3-提示成功
                this.$emit('input', birthday)
                this.$emit('close')
                this.$toast('修改成功')
            } catch (error) {
                this.$toast('选择生日失败', error)
            }
        },
    }
}
</script>
<style lang='less'  scoped></style>
